import { PureComponent } from "react";
import GrandContext from "../context/grandContext";
import ClassChild from './child';
import FnChild from '../fnCom/child';

class Parent extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            count: 0
        }
    }

    increment = () => {
        this.setState({
            count: this.state.count + 1
        })
    }

    render() {
        return (
            <GrandContext.Consumer>
                {(value) => {
                    return (
                        <div className="border mt10">
                            <p className="title">Parent</p>
                            <h2>{JSON.stringify(value)}</h2>
                            <p>当前计数：{this.state.count}</p>
                            <button onClick={this.increment}>Parent里面的++++</button>
                            <br />
                            <ClassChild increment={this.increment} {...this.props}/>
                            <FnChild/>
                        </div>
                    )
                }}
            </GrandContext.Consumer>
        )
    }
}

export default Parent;